using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Super_Pong
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        ComputerPlayer player1, player2;
        Ball ball;
        ComputerPlayer.CPU Difficulty;
        SpriteFont font;
        Song musica;
        
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            IsMouseVisible =true;
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            ball = new Ball(Content, Window, "Sprites/ball");
            player1 = new ComputerPlayer(Content, Window, "Sprites/bar", "left", new Vector2(0, 180));
            player2 = new ComputerPlayer(Content, Window, "Sprites/bar", "right", new Vector2(0, 180));
            Difficulty = ComputerPlayer.CPU.Easy;
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("myFont");
            musica = Content.Load<Song>("Bon Jovi - It's My Life");
            MediaPlayer.Play(musica);

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            player1.update(gameTime, Window, ball);
            player2.update(gameTime, Window, ball);
            ball.update(gameTime, Window, player1, player2);
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
            player1.draw(spriteBatch);
            player2.draw(spriteBatch);
            ball.draw(spriteBatch);
            player1.drawPoints(Window, spriteBatch, font, "left");
            player2.drawPoints(Window, spriteBatch, font, "right");
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
